package android.slc.appbase.ui.vd.wrapper;

import android.slc.appbase.api.slc.callback.SlcObserver;
import android.slc.box.or.OnResultsListener;
import android.slc.box.or.SlcCallbackConfig;

public class BaseListCommonWrapper<T> implements IBaseListCommonWrapper<T> {
    protected final OnResultsListener<T> onResultsListener;

    public BaseListCommonWrapper(OnResultsListener<T> onResultsListener) {
        this.onResultsListener = onResultsListener;
        createDataListSlcObserver();
    }

    private SlcObserver<T> dataListSlcObserver;

    protected SlcObserver<T> createDataListSlcObserver() {
        return createDataListSlcObserver(SlcCallbackConfig.newBuilder().showToast(false).build());
    }

    protected SlcObserver<T> createDataListSlcObserver(SlcCallbackConfig slcCallbackConfig) {
        return dataListSlcObserver = new SlcObserver<T>(slcCallbackConfig) {
            @Override
            protected void onSucceed(T data) {
                BaseListCommonWrapper.this.onSucceed(data);
            }

            @Override
            protected void onFailed(int errorCode, String errorMessage) {
                BaseListCommonWrapper.this.onError(errorCode, errorMessage);
            }
        };
    }

    @Override
    public SlcObserver<T> getDataListSlcObserver() {
        return dataListSlcObserver;
    }

    @Override
    public void onSucceed(T data) {
        this.onResultsListener.onSucceed(data);
    }

    @Override
    public void onError(int errorCode, String errorMessage) {
        this.onResultsListener.onError(errorCode, errorMessage);
    }
}
